|
|
|
|
|
|
|
Figure 12.9
Arcs and rectangles that Visual Basic's Circle
and Line methods cannot draw directly. |
|
|
|
|
|
|
|
|
While the most general transformations possible are quite complicated, you can build many useful transformations by combining simple translation, scaling, and rotation. The next several sections describe these simpler transformations. The sections following those explain how you can compose these simple transformations to create more general ones. |
|
|
|
|
|
|
|
|
To translate an object, you add an appropriate offset to the X and Y coordinates of the points that make up the object. For example, to move an object 10 units in the positive X direction and 3 units in the negative Y direction in world coordinates, add 10 to the X coordinate and subtract 3 from the Y coordinate of each point in the object. You can write the new coordinates of a point as: |
|
|
|
 |
|
|
|
|
new_x = old_x + x_offset
new_y = old_y + y_offset |
|
|
|
|
|
|
|
|
It is just as easy to scale an object. To scale or stretch an object in the X direction, multiply the X coordinate of each of the object's points by some number. For example, to make an object twice as wide, multiply the X coordinates of its points by a factor of two. You can scale an object in the Y direction similarly. You can write the new coordinates of a point as: |
|
|
|
 |
|
|
|
|
new_x = old_x * x_scale
new_y = old_y * y_scale |
|
|
|
|
|
|
|
|
Figure 12.10 shows a picture before and after it has been scaled by a factor of 2 in the X direction. Notice that multiplying each point's X coordinate has moved the object twice as far from the Y axis as it was before. |
|
|
|
|
|